/**
 *	2.
**/

#include <stdio.h>
#include <float.h>

float single_tax(float income);

int main()
{
	

	return 0;
}

// 普通方法
float single_tax(float income)
{
	if(income > 256500)
		return 81710.5 + 0.396 * (income - 256500);
	if(income > 117950)
		return 31832.5 + 0.36 * (income - 117950);
	if(income > 56550)
		return 12798.5 + 0.31 * (income - 56550);
	if(income > 23350)
                return 3502.5 + 0.28 * (income - 23350);
	if(income > 0)
                return 0.15 * income;

	return 0;
}

// 查表法
static double income_limits[] = {
	0, 23350, 56550, 117950, 256500, DBL_MAX
};

static float base_tax[] = {
	0, 3502.5, 12798.5, 31832.5, 81710.5
};

static float percentage[] = {
	0.15, 0.28, 0.31, 0.36, 0.396
};

double single_tax1(double income)
{
	int category;
	for(category = 1; income >= income_limits[category]; category++)
		;
	category--;
	return base_tax[category] + percentage[category] * (income - income_limits[category]);
}
